<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>通讯录</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
</head>
<body>
    <section class="aui-content">
      <div class="aui-card-list">
          <div class="aui-card-list-content">
              <ul id="users-list" class="aui-list aui-media-list">

              </ul>
          </div>
      </div>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript">
apiready = function(){
     $api.setStorage("dm_index", 0);
     load();
     //上拉翻页
     api.addEventListener({
         name : 'scrolltobottom'
     }, function(ret, err) {
         $api.setStorage("dm_index", $api.getStorage("dm_index") - 0 + 1);
         load();
     });
 }

//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("dm_index");
     var url = ServeUrl + "m=Daily&a=userInfo&pageIndex=" + index + "&pageCount=15";
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
             alert("没有更多的用户！");
             api.hideProgress();
         }
     });
 }

//字符串拼接
 function dealWithHtml(data, first, index) {
     var member = api.pageParam.member;
    //alert(member);
     var html = '';
     for (var i = 0; i < data.data.length; i++) {
          html += '<li class="aui-list-item aui-list-item-middle">'
          html += '<div class="aui-media-list-item-inner">'
          html += '<div class="aui-list-item-media" style="width: 3rem;">'
          html += '<img src="'+ServeIp+'include/data/headImg/'+data.data[i].user_img+'" class="aui-img-round">'
          html += '</div>'
          html += '<div class="aui-list-item-inner ">'
          html += '<div class="aui-list-item-text">'
          html += '<div class="aui-list-item-title aui-font-size-14">'+data.data[i].cn_name+'</div>'
          html += '<div class="aui-list-item-right">'
          //alert(member.indexOf(data.data[i].username));
          if(member){
              if(member.indexOf(data.data[i].username) >= 0 ){
                  html += '<input type="checkbox" disabled name="username" class="aui-checkbox" value="'+data.data[i].username+'" >'
              }else {
                  html += '<input type="checkbox" name="username" class="aui-checkbox" value="'+data.data[i].username+'" >'
              }
          }else {
              html += '<input type="checkbox" name="username" class="aui-checkbox" value="'+data.data[i].username+'" >'
          }

          html += '</div>'
          html += '</div>'
          html += '</div>'
          html += '</div>'
          html += '</li>';
     }
    $("#users-list").append(html);
    api.hideProgress();

 }

//选择用户
 function selectUsers(){
    var winName= api.pageParam.winName;
    var frameName=api.pageParam.frameName;
    var member = api.pageParam.member;
     obj = document.getElementsByName("username");
     check_val = [];
     for(k in obj){
         if(obj[k].checked)
             check_val.push(obj[k].value);
     }
     var check_str = check_val.join(",");
     if(member){
         var jsfun = 'selectUsers("'+check_str+'","'+member+'");';
     }else {
         var jsfun = 'selectUsers("'+check_str+'");';
     }
     api.execScript({
         name : winName,
         frameName: frameName,
         script: jsfun
     });
 }



</script>
</html>
